<?php
class IndexController extends BaseController {
	public function index(){
		$data['levelList']  = HttpDaoManager::getLevelDao()->searchList('',' order by level desc ');
		$data['information'] = HttpDaoManager::getNewsDao()->searchList(array('news_class_id'=>5),'',8);
		$data['informationOne'] = HttpDaoManager::getNewsDao()->searchList(array('news_class_id'=>5,'status'=>NEWS_STATUS_RECOM),'',1);
		if (isset($_SESSION['user'])){
			$data['user']['user_moeny'] = $_SESSION['user']['user_moeny'];
			$data['user']['integral'] = $_SESSION['user']['integral'];
			$data['user']['user_class_left'] = $_SESSION['user']['user_class']+$_SESSION['user']['user_monthly_class'];
			$data['user']['complete'] = HttpDaoManager::getBookCourseDao()->searchNumber(array('class_status'=>CLASS_STATUS_2,'user_id'=>$_SESSION['user']['id']));
			$data['user']['completeHour'] = round(25/60*$data['user']['complete'],2) ;
			$data['user']['voucher'] = HttpDaoManager::getTicketDao()->searchNumber(array('receive_user_id'=>$_SESSION['user']['id'],'status'=>TICKET_STATUS_2,'valid_start_time' => array(time(),'<='),'valid_end_time' => array(time(),'>=')));
		}
		
		$data['course_type'] = Common::_t('course_type');
		$data['student']= HttpDaoManager::getNewsDao()->searchList(array('nav_id'=>84),' order by id desc ',3);
		$data['teacher']= HttpDaoManager::getNewsDao()->searchList(array('nav_id'=>81),' order by id desc ',3);
		$data['course'] = HttpDaoManager::getCourseTypeDao()->searchList(array('status'=>COURSE_TYPE_STATUS_2));
		$course_type_list = array();
		foreach($data['course']  as $key=>$value){
			$course_type_list[$value['type']][$value['course_type']]['id']= $value['id'];
			$course_type_list[$value['type']][$value['course_type']]['course_type']= $value['course_type'];
			$course_type_list[$value['type']][$value['course_type']]['name']= $data['course_type'][$value['course_type']];
		}
		$data['course_type_list'] = $course_type_list;
		$data['english_type'] =  Common::_t('english_type');
		
		$purposeDao = HttpDaoManager::getPurposeDao();
		$data['purpose'] =$purposeDao->getListByFatherId(0);
		foreach ($data['purpose'] as $v){
			$data['purpose1'][$v['id']] = $purposeDao->getListByFatherId($v['id']);
		}
		$level_list = array();
		foreach($data['levelList'] as $k=>$v){
			if(isset($v['subject'])&&trim($v['subject'])!=""){
				$level_list[$k]['level']=$v['level'];
				//$level_list[$k]['subject']='Level-'.$v['level'].':'.$v['subject'];
				$level_list[$k]['subject']=$v['subject'];
			}
		}
		$data['level_list'] = $level_list;
		$level_purpose_list = array();
		foreach($data['levelList'] as $k=>$v){
			if(isset($v['target'])&&trim($v['target'])!=""){
				$level_purpose_list[$k]['level']=$v['level'];
				//$level_purpose_list[$k]['target']='Level-'.$v['level'].':'.$v['target'];
				$level_purpose_list[$k]['target']=$v['target'];
			}
		}
		$data['level_purpose_list'] = $level_purpose_list;	
		if(isset($_COOKIE['COOKIE_LOGIN_NAME'])&&!empty($_COOKIE['COOKIE_LOGIN_NAME'])){
			$data['login_user_name']= $_COOKIE['COOKIE_LOGIN_NAME'];
		}
		$index = HttpServerManager::getIndexIncludeServer();	
		$url = $index->getUrl();
		$url_info = HttpDaoManager::getNavDao()->getByUrl($url);
		$data['top'] = $index->getTop($url_info);
		
		return $data;
	}
	
	public function login(){
		$data = array();
		if(isset($_COOKIE['COOKIE_LOGIN_NAME'])&&!empty($_COOKIE['COOKIE_LOGIN_NAME'])){
			$data['login_user_name']= $_COOKIE['COOKIE_LOGIN_NAME'];
		}
		return $data;		
	}
	
	public function subLogin(){
		$result = array();
		$result['res_code']=99;		
		$domain=strtolower(substr($_POST['email'],stripos($_POST['email'],'@')));
		$mail_name = substr($_POST['email'],0,stripos($_POST['email'],'@'));
		$email=$mail_name.$domain;
		$tmp = HttpServerManager::getUserServer()->login($email, $_POST['password']);
		$result['res_code'] = $tmp;
		exit(json_encode($result));
	}
	public function register(){
		$data =  HttpServerManager::getIndexIncludeServer()->getPublic();
		return $data;		
	}

	public function change(){
		$data =  HttpServerManager::getIndexIncludeServer()->getPublic();
		return $data;	
			
	}
	public function subRegister(){
		$result = array();
		$result['res_code']=99;
		$data = $_POST;
		if (isset($_COOKIE['invitation_user_id'])){
			$data['invitation_user_id'] = $_COOKIE['invitation_user_id'];
		}
		
		if (isset($_COOKIE['invitation_funduser_id'])){
			$data['fund_user_id'] = $_COOKIE['invitation_funduser_id'];
		}
		
		$tmp = HttpServerManager::getUserServer()->registerAndLogin($data);
		$result['success'] = 'fail';
		$result['res_code'] = $tmp;
		if($tmp===true){
			$result['success'] = 'success';
		}
		exit(json_encode($result));
	}
	
	public function us(){
		if(isset($_GET['id'])){
			$tmp = $_GET['id'];
		}
		if(!isset($_GET['id'])||!Common::is_number($_GET['id'])){
			$tmp=0;
			$url = HttpServerManager::getIndexIncludeServer()->getUrl();
			$url_info = HttpDaoManager::getNavDao()->getByUrl($url);
			$first_url_info = HttpDaoManager::getNavDao()->getFirstLinkByFather_id($url_info['id']);
			$tmp=$first_url_info['id'];
		}
		$data =  HttpServerManager::getIndexIncludeServer()->getPublic();
		$father_nav = $data['left']['father_nav'];
		$news_type = $father_nav['news_type'];
		if($news_type == NEWS_PUB_TYPE_SINGLE){
				$news = HttpDaoManager::getNewsDao()->getNewInfoByNavId($tmp);
				$data['news'] = $news;
		}
		$data['news_type'] = $news_type;

		return $data;
	}
	
	
	public function promotion(){
		$data =  HttpServerManager::getIndexIncludeServer()->getPublic();
		return $data;
	}
	
	public function share(){
		if(isset($_GET['id'])){
			$tmp = $_GET['id'];
		}
		if(!isset($_GET['id'])||!Common::is_number($_GET['id'])){
			$tmp=0;
			$url = HttpServerManager::getIndexIncludeServer()->getUrl();
			$url_info = HttpDaoManager::getNavDao()->getByUrl($url);
			$first_url_info = HttpDaoManager::getNavDao()->getFirstLinkByFather_id($url_info['id']);
			$tmp=$first_url_info['id'];
		}
		$data =  HttpServerManager::getIndexIncludeServer()->getPublic();
		$father_nav = $data['left']['father_nav'];
		$news_type = $father_nav['news_type'];
		if($news_type == NEWS_PUB_TYPE_SINGLE){
			$news = HttpDaoManager::getNewsDao()->getNewInfoByNavId($tmp);
			$data['news'] = $news;
		}
		$data['news_type'] = $news_type;
		return $data;
	}
	
	
	public function tnews(){//新闻发布列表
		if(isset($_GET['id'])){
			$tmp = $_GET['id'];
		}
		if(!isset($_GET['id'])||!Common::is_number($_GET['id'])){
			header('location:index.html');
			exit;
		}
		$data =  HttpServerManager::getIndexIncludeServer()->getPublic($tmp);
		$father_nav = $data['left']['father_nav'];
		$news_type = $father_nav['news_type'];
		$nav = HttpDaoManager::getNavDao()->get($tmp);
		$data['nav'] = $nav;

		$data['news_type'] = $news_type;
		$where['nav_id'] = $tmp;
		$where['type'] = NEWS_PUB_TYPE_LIST;
		$order_by = ' order by recom_status desc,id desc ';
		$data['news_list'] = HttpServerManager::getNewsServer()->paging($where,$order_by,5);
		return $data;
	}
	
	public function newsdetail(){//新闻发布详细页面
		if(isset($_GET['id'])){
			$tmp = $_GET['id'];
		}
		if(!isset($_GET['id'])||!Common::is_number($_GET['id'])){
			header('location:index.html');
			exit;
		}
		$data =  HttpServerManager::getIndexIncludeServer()->getPublic($tmp);
		$father_nav = $data['left']['father_nav'];
		$news_type = $father_nav['news_type'];
		$news = HttpDaoManager::getNewsDao()->get($tmp);
		$data['news'] = $news;
		$nav_left_parent = HttpDaoManager::getNavDao()->get($news['nav_id']);
		$nav_index_parent = HttpDaoManager::getNavDao()->get($nav_left_parent['father_id']);
		$data['nav_left_parent'] = $nav_left_parent;
		$data['nav_index_parent'] = $nav_index_parent;
		return $data;
	}
	
	public function pubnews(){
		if(isset($_GET['id'])){
			$tmp = $_GET['id'];
		}
		if(!isset($_GET['id'])||!Common::is_number($_GET['id'])){
			$url = HttpServerManager::getIndexIncludeServer()->getUrl();
			$url_info = HttpDaoManager::getNavDao()->getByUrl($url);
			$first_url_info = HttpDaoManager::getNavDao()->getFirstLinkByFather_id($url_info['id']);
			$tmp=$first_url_info['id'];
		}
		
		$data =  HttpServerManager::getIndexIncludeServer()->getPublic();
		$father_nav = $data['left']['father_nav'];
		$news_type = $father_nav['news_type'];
		$data['news_type'] = $news_type;

		$news_left_info = HttpDaoManager::getNavDao()->get($tmp);
		$where['nav_id'] = $tmp;
		$where['type'] = NEWS_PUB_TYPE_LIST;
		$order_by = ' order by recom_status desc,id desc ';
		$data['news_list'] = HttpServerManager::getNewsServer()->paging($where,$order_by,5);	
		$data['news_left_info'] = 	$news_left_info;
		return $data;
	}
	
	public function assess(){
		$data['list']  = HttpDaoManager::getLevelDao()->searchList('',' order by level asc ');
		$level_list = array();
		foreach($data['list'] as $k=>$v){
			if(isset($v['subject'])&&trim($v['subject'])!=""){
				$level_list[$k]['level']=$v['level'];
				//$level_list[$k]['subject']='Level-'.$v['level'].':'.$v['subject'];
				$level_list[$k]['subject']=$v['subject'];
			}
		}		
		$data['level_list'] = $level_list;
		$level_purpose_list = array();
		foreach($data['list'] as $k=>$v){
			if(isset($v['target'])&&trim($v['target'])!=""){
				$level_purpose_list[$k]['level']=$v['level'];
				//$level_purpose_list[$k]['target']='Level-'.$v['level'].':'.$v['target'];
				$level_purpose_list[$k]['target']=$v['target'];
			}
		}		

		$data['level_purpose_list'] = $level_purpose_list;
		$purposeDao = HttpDaoManager::getPurposeDao();
		$data['purpose'] =$purposeDao->getListByFatherId(0);
		$data['purpose_pair1'] = array();
		foreach ($data['purpose'] as $v){
			$data['purpose_pair1'][$v['id']] = $purposeDao->getListByFatherId($v['id']);
		}
		
		if(isset($_POST['search_flg'])&&$_POST['search_flg']>0){
			$data['search_flg'] = $_POST['search_flg'];			
			$data['select_purpose'] = $_POST['purpose'];			
			$data['select_purpose_people'] = $_POST['purpose_people'];		
			$data['select_level'] = $_POST['level'];			
			$data['select_target'] = $_POST['target'];
		}
		//推荐教材
		$where = array();
		if(isset($data['select_level'])&&$data['select_level']>=0&&isset($data['select_target'])&&$data['select_target']>=0){
			$where['start_level'] = $data['select_level'];
			$where['end_level'] = $data['select_target'];
			$where['for_purpose_study'] = $data['select_purpose'];
			$where['for_purpose_pepople'] = $data['select_purpose_people'];
			$order_by = 'order by type desc';
		}else{
			$where['course_recommend'] = 1;//推荐教材
			$order_by = 'order by id,course_recommend desc';
		}		

		$courseList = HttpDaoManager::getCourseDao()->searchList($where,$order_by,4);
		$course_type_pair =Common::_t('course_type');

		$course_id_list = Common::array_value_list($courseList,'id');
		$course_id_list_str = implode(',',$course_id_list);
		$chapterList = HttpDaoManager::getChapterDao()->getListByCourseIdList($course_id_list_str,'1');
		$chapterPair = array();
		foreach($chapterList as $key=>$value){
			$chapterPair[$value['course_id']] = $value['id'];//chapter_id
		}
		
		$courseListData = array();
		foreach($courseList as $key=>$value){
			if($value['id']>0){
				$courseListData[$value['type']]['course_type_name'] = $course_type_pair[$value['type']];
				$courseListData[$value['type']][$value['id']] = $value;
				$start_level = $value['level']-1;
				$end_level = $value['level']+1;
				if($start_level<0){
					$start_level=1;
				}
				$courseListData[$value['type']][$value['id']]['start_level']=$start_level;
				$courseListData[$value['type']][$value['id']]['end_level']=$end_level;
				$coursse_url_id = $value['id'];
				$up = Common::encryptUrl($coursse_url_id);
				$sa = Common::encryptUrl(SA_URL_COURSE);
				$courseListData[$value['type']][$value['id']]['course_view'] = SITE_URL.'browse.html?sa='.$sa.'&up='.$up;
				
				$sa = Common::encryptUrl(SA_URL_CHAPTER);
				$chapter_url_id = $chapterPair[$value['id']];
				$up = Common::encryptUrl($chapter_url_id);
				$courseListData[$value['type']][$value['id']]['chapter_view'] = SITE_URL.'browse.html?sa='.$sa.'&up='.$up;
			}
		}
		$data['courseListData'] = $courseListData;
		return array_merge($data, HttpServerManager::getIndexIncludeServer()->getPublic());
	}
  	public function course(){
  		$data['course1'] =  HttpDaoManager::getCourseTypeDao()->searchList(array('type'=>COURSE_TYPE_TYPE_1));
  		$data['course2'] =  HttpDaoManager::getCourseTypeDao()->searchList(array('type'=>COURSE_TYPE_TYPE_2));
  		$data['course3'] =  HttpDaoManager::getCourseTypeDao()->searchList(array('type'=>COURSE_TYPE_TYPE_3));
  		$data['course4'] =  HttpDaoManager::getCourseTypeDao()->searchList(array('type'=>COURSE_TYPE_TYPE_4));
  		$data['course5'] =  HttpDaoManager::getCourseTypeDao()->searchList(array('type'=>COURSE_TYPE_TYPE_5));
  		$data['courseType'] = Common::_t('course_type');
  		return array_merge($data,HttpServerManager::getIndexIncludeServer()->getPublic());
  	}
  	
  	public function processClass(){
  		return HttpServerManager::getIndexIncludeServer()->getPublic();
  	}

  	public function hotbox(){
  		return HttpServerManager::getIndexIncludeServer()->getPublic();
  	}
  	
  	public function courseInfo(){
  		$id  = $_GET['id'];
  		$id = intval($id);
  		if($id==0){
  			header('location:course.html');
  			exit;
  		}
  		if(isset($id)&&$id>0){
	  		$data = HttpDaoManager::getCourseTypeDao()->get($_GET['id']);
	  		$course_type_pair =Common::_t('course_type');
	  		
	  		if($data['course_type']>0){
		  		$where = array();
		  		$where['type'] = $data['course_type'];
				$courseList = HttpDaoManager::getCourseDao()->searchList($where);
				
				if(!empty($courseList)){
					$course_id_list = Common::array_value_list($courseList,'id');
					$course_id_list_str = implode(',',$course_id_list);
					
					$chapterList = HttpDaoManager::getChapterDao()->getListByCourseIdList($course_id_list_str,'1');
					$chapterPair = array();
					foreach($chapterList as $key=>$value){
						$chapterPair[$value['course_id']] = $value['id'];//chapter_id
					}
					
					$level_list = HttpDaoManager::getLevelDao()->searchList();
					$level_pair = array();
					foreach($level_list as $k=>$v){
						if(isset($v['id'])){
							//$level_pair[$v['id']]='Level'.'-'.$v['level'].':'.$v['subject'];
							$level_pair[$v['id']]['level']='Level'.'-'.$v['level'];
							$level_pair[$v['id']]['subject']=$v['subject'];
						}
					}
					
					$courseListData = array();
					foreach($courseList as $key=>$value){
						if($value['id']>0){
							$courseListData[$value['type']]['course_type_name'] = $course_type_pair[$value['type']];
							$courseListData[$value['type']][$value['id']] = $value;
	
							$coursse_url_id = $value['id'];
							$up = Common::encryptUrl($coursse_url_id);
							$sa = Common::encryptUrl(SA_URL_COURSE);
							$courseListData[$value['type']][$value['id']]['course_view'] = SITE_URL.'browse.html?sa='.$sa.'&up='.$up;
							
							$chapter_url_id = $chapterPair[$value['id']];
							$up = Common::encryptUrl($chapter_url_id);
							$sa = Common::encryptUrl(SA_URL_CHAPTER);
							$courseListData[$value['type']][$value['id']]['chapter_view'] = SITE_URL.'browse.html?id='.$chapter_url_id.'&sa='.$sa.'&up='.$up;
						}
					}
					
					$data['courseListData'] = $courseListData;
					$data['level_pair']= $level_pair;
				}
				
	  		}
	  		
	  		return array_merge($data,HttpServerManager::getIndexIncludeServer()->getPublic('course.htm'));
  		}else{
	  		header('location:index.html');
  		}
  	}
  	public function pay(){
  		return HttpServerManager::getIndexIncludeServer()->getPublic();
  	}
  	public function newsList(){
  		$news_id = Common::getGetStrValue('classId');
		if(!Common::is_number($news_id)){
			header('location:teacher.html');
			exit;
		}
  		$tmp = HttpDaoManager::getNewsClassDao()->get($news_id);
  		$data = HttpServerManager::getNewsServer()->paging(array('news_class_id'=>$news_id),3);
  		$data['title'] = $tmp['title'];
  		return array_merge($data,HttpServerManager::getIndexIncludeServer()->getPublic());
  	}
  	public function help(){
  		return HttpServerManager::getIndexIncludeServer()->getPublic();
  	}
  	
  	public function userInvitation(){
  		if (isset($_GET['invitation_user_id'])){
  			setcookie("invitation_user_id", $_GET['invitation_user_id'], time()+86400);
  		}
  		header("Location:register.html");
  	}
  	
  	public function funduserInvitation(){
  		if (isset($_GET['type'])){
  			$type = Common::decryptUrl($_GET['type'],'fd');
  			$id = Common::decryptUrl($_GET['id'],'fd');
  			setcookie("invitation_funduser_id", $id, time()+86400*30);
  		}
  		header("Location:register.html");
  	}
  	
  	public function price(){
  		$productDao  = HttpDaoManager::getProductDao();
  		$product_monthly_list= $productDao->searchList(array('type'=>PRODUCT_TYPE_1,'status'=>PRODUCT_STATUS_1));
  		$product_data = array();
  		foreach($product_monthly_list as $k=>$v){
  			$product_data[$v['unit']][$v['id']]=$v;
  		}
  		ksort($product_data);
  		$data['product'][PRODUCT_TYPE_1] = $product_data;
  		
  		$product_card_list = $productDao->searchList(array('type'=>PRODUCT_TYPE_2,'status'=>PRODUCT_STATUS_1,'active_type'=>ACTIVE_TYPE_1));
  		$product_data = array();
  		foreach($product_card_list as $k=>$v){
  			$product_data[$v['unit']][$v['id']]=$v;
  		}
  		ksort($product_data);
  		$data['product'][PRODUCT_TYPE_2] = $product_data;
  		$productReturnTicketList = $productDao->searchList(array('type'=>PRODUCT_TYPE_3,'status'=>PRODUCT_STATUS_1));
  		$data['returnTicketPair'] = Common::fetchPairOfList('id', 'price', $productReturnTicketList);  		
  		return array_merge($data,HttpServerManager::getIndexIncludeServer()->getPublic());
  	}
  	public function guide(){
  		return  HttpServerManager::getIndexIncludeServer()->getPublic();
  	}
  	public function  aliNotify(){
  		$alipay = new Alipay();
  		$tmp = $alipay->notify($_POST);
  	  	if ($tmp===true){
  		  	$out_id = $_POST['out_trade_no'];
  		  	$total_fee = $_POST['total_fee'];
  		  	HttpServerManager::getOrderServer()->updateNotifyPayInfo($out_id,$total_fee);
  			exit ('success');
  		}
  		else{
  			exit('fail');
  		}
  	}
  	public function tenNotify(){
  		$tenpay = new Tenpay();
  		$tmp = $tenpay->notify($_GET);
  		if ($tmp ===true){
  		  	$out_id = $_GET['out_trade_no'];
  		  	$total_fee = $_GET['total_fee'];
  		  	HttpServerManager::getOrderServer()->updateNotifyPayInfo($out_id,$total_fee);
  			exit ('success');
  		}
  		else{
  			exit('fail');
  		}
  	}
  	
  	public function forgotPassword(){
  		return  HttpServerManager::getIndexIncludeServer()->getPublic();
  	}
  	
  	public function download(){
  		return  HttpServerManager::getIndexIncludeServer()->getPublic();
  	}
  	
  	public function femaleName(){
  		return  HttpServerManager::getIndexIncludeServer()->getPublic();
  	}
  	
  	public function maleName(){
  		return  HttpServerManager::getIndexIncludeServer()->getPublic();
  	}
  	
  	public function sendVerification(){
  		$send_result = array();
  		$tmp = HttpServerManager::getUserServer()->sendVerification($_POST['email']);
  		if($tmp === USER_ERROR_18){
  			$send_result = array('success'=>'fail_mail_user');
  			exit(json_encode($send_result));
  		}
  		$send_result = array('success'=>'success');
  		exit(json_encode($send_result));
  	}
  	
  	public function sendCode(){
  		$phone= $_POST['phone'];
  		$send_result = array();
  		if(isset($phone)&&empty($phone)){
  			$send_result = array('success'=>'fail_phone');
  			exit(json_encode($send_result)); 			
  		}
  		$user_info = HttpDaoManager::getUserDao()->getByPhone($phone);
  		if(empty($user_info)){
  			$send_result = array('success'=>'fail_phone_user');
  			exit(json_encode($send_result));
  		}
  		$sms_send = HttpServerManager::getUserServer()->sendForgotCode($phone);
  		$send_result = array('success'=>'success');
  		exit(json_encode($send_result));
  	}  	
  	
  	public function browse(){
  		global $browser_course_url;
  		global $browser_chapter_url;
  		$url_parameter_up = $_GET['up'];
  		$url_parameter_sa = $_GET['sa'];
  		$url_id = Common::decryptUrl($url_parameter_up);
  		$url_sa = Common::decryptUrl($url_parameter_sa);
  		$url_info = array();
  		$browser_url ="";
  		
  		if($url_sa == SA_URL_COURSE){
	  		$course_info = HttpServerManager::getCourseServer()->userGet($url_id);
	  		if(!empty($course_info)){
	  			$url_info = $course_info[0];
	  			$url_info['document']= $url_info['teaching_material'];
	  			$browser_url = $browser_course_url;
	  		}
  		}elseif($url_sa == SA_URL_CHAPTER){
	  		$chapter_info = HttpServerManager::getChapterServer()->userGet($url_id);
	  		if(!empty($chapter_info)){
	  			$url_info = $chapter_info[0];
	  			$browser_url = $browser_chapter_url;
	  		}
  		}
  		
  		$newname = '';
  		$newflg = '';
  		if(!empty($url_info)){
	  		$document = $url_info['document'];
	  		if($url_sa == SA_URL_COURSE){
	  			$newflg = md5($url_info['id'].'cou',false);
	  		}elseif($url_sa == SA_URL_CHAPTER){
		  		$newflg = md5($url_info['course_id'].'cha',false);
	  		}
	  		$pos = strripos($document, '/');
	  		if($pos>0){
	  			$len = strlen($document);
	  			$old_name = substr($document,1,$pos);
	  			$newname = substr($document,$pos+1,$len-$pos);
	  		}
	  		if(!empty($document)){
	  			$cp_newname = $newflg.'_'.$newname;
	  			if(!file_exists(WEB_DIR.$browser_url.$cp_newname)){
			  		$flg = copy(WEB_DIR.$old_name.$newname, WEB_DIR.$browser_url.$cp_newname);
			  		if($flg==true){
				  		header('location:'.SITE_URL.$browser_url.$cp_newname);
			  		}
	  			}
		  		header('location:'.SITE_URL.$browser_url.$cp_newname);
	  		}
  		}
  		exit;
  	}
  	
  	public function broseUrl(){
  	}
  	
  	public function teacher(){
  		$data  = HttpServerManager::getTeacherServer()->lists();
  		
  		return  array_merge($data,HttpServerManager::getIndexIncludeServer()->getPublic());
  	}  	
  	
  	public function updateForgotPassword(){
  		$code_way = $_POST['code_way'];
  		$code = $_POST['code'];
  		$code_way_tool = $_POST['code_way_tool'];
  		$password = $_POST['password'];
  		$confirm_password = $_POST['confirm_password'];
  		$res = array();
  		if(!isset($_SESSION['forgotPasswordValidation'])){
  			$res['success']='fail_code_info';
  			exit(json_encode($res));
  		}
  		
  		if($code!=$_SESSION['forgotPasswordValidation']['code']){
  			$res['success']='fail_code';
  			exit(json_encode($res));
  		}
  		if($code_way=='phone'){
  		  	if($code_way_tool!=$_SESSION['forgotPasswordValidation']['phone']){
	  			$res['success']='fail_user';
	  			exit(json_encode($res));
  			}
  		}
  		
  		if($code_way=='email'){
  			if($code_way_tool!=$_SESSION['forgotPasswordValidation']['email']){
	  			$res['success']='fail_user';
	  			exit(json_encode($res));
  			}
  		}

  		$tmp = HttpServerManager::getUserServer()->forgotPassword($_POST);
  		if ($tmp===true){
  			$res['success']='success';
  			 exit(json_encode($res));
  		}
  		else{
  			$res['success']='fail';
  			 exit(json_encode($res));
  		}
  	}
  	
  	public function qqLogin(){
  		$qc = new QC();
		$qc->qq_login();
  	}
  	
  	public function qqConnectBack(){
  		$qc = new QC();
  		$accessToken = $qc->qq_callback();
 		$openId = $qc->get_openid();
		$_SESSION['qq_cc']['accessToken'] = $accessToken;
		$_SESSION['qq_cc']['openId'] = $openId;
 		header('location:'.SITE_URL.'qqConnectLogin.htm');
  	}
 
  	public function qqConnectLogin(){
  		$qqInfo = array();
  		$qc = new QC($_SESSION['qq_cc']['accessToken'],$_SESSION['qq_cc']['openId']);
  		$qqInfo = $qc->get_user_info();
  		$_SESSION['qq_cc']['qqInfo'] = $qqInfo;
  		if($qqInfo['ret']=='0'){
  			$qqLoginInfo = HttpDaoManager::getUserDao()->qqUserget($_SESSION['qq_cc']['openId']);
  			if(empty($qqLoginInfo)){
  				$userInfo = array();
  				$userInfo['sex'] = SEX_MALE;
  				if(trim($qqInfo['gender'])=='女'){
  					$userInfo['sex'] = SEX_FEMALE;
  				}
  				$userInfo['openid'] = $_SESSION['qq_cc']['openId'];
  				$userInfo['nickname'] = $qqInfo['nickname'];
  				$userInfo['register_time'] = time();
  				$userInfo['register_type'] = REGISTER_TYPE_QQ;
  				HttpDaoManager::getUserDao()->add($userInfo);
  				unset($userInfo);
  			}
  			
  			$qqLoginInfo = HttpDaoManager::getUserDao()->qqUserget($_SESSION['qq_cc']['openId']);
  			$_SESSION['user'] = $qqLoginInfo;
  		}
  		return $qqInfo;
  	}
  	
  	public function mailConfirm(){
  		$verify_id = $_REQUEST['verify_id'];
  		if(empty($verify_id)){
  			ClassManager::getToos()->msgbox('验证失败,请重新验证','index.htm');
  		}
  		$id  = Common::decryptUrl($verify_id,'128592');
  		$id = substr($id,stripos($id,'_')+1);
  		$userEmailInfo = HttpDaoManager::getUserDao()->get($id);
  		if(!empty($userEmailInfo)){
  			if($userEmailInfo['qq_bind_status']!=QQ_BIND_UNCONFIRM){
  				if($userEmailInfo['qq_bind_status']==QQ_BIND_SUCCESS){
	  				ClassManager::getToos()->msgbox('该用户已被其他人绑定','index.htm');
  				}
  				if($userEmailInfo['qq_bind_status']==QQ_FAIL){
	  				ClassManager::getToos()->msgbox('请重新绑定该用户','index.htm');
  				}
  			}
  			$where = array();
  			$where['qq_bind_status'] = QQ_BIND_UNCONFIRM;
  			$where['qq_bind_id'] = $id;
  			$userQQList = HttpDaoManager::getUserDao()->searchList($where);
  			//验证通过，数据绑定
  			$userQQInfo = array();
  			if(!empty($userQQList)){
  				$userQQInfo = $userQQList[0];
  			}
  			$qqUserId = $userQQInfo['id'];
  			$bindFlg = HttpServerManager::getUserServer()->bindUserAndQQ($id,$qqUserId);//更新关联数据
  			if($bindFlg == true){
	  			ClassManager::getToos()->msgbox('验证成功','user_home.htm');
  			}else{
	  			ClassManager::getToos()->msgbox('验证失败','index.htm');
  			}
  		}
  	}
}
?>